package com.dorm.cj.design.demo;

import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;

import javax.persistence.Transient;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class Base implements Serializable {

    private static final long serialVersionUID = -6259607078493445704L;
    @Transient
    protected Map<String, Object> extra = new HashMap<>();

    public Base() {
    }

    public Base(Map<String, Object> extra) {
        this.extra = extra;
    }

    @JsonAnySetter //反序列化时，位置属性调用
    public void set(String key, String value) {
        this.extra.put(key, value);
    }

    public void get(String key) {
        this.extra.get(key);
    }

    @JsonAnyGetter // 序列化时，将map下的key,value全部解析到bean属性同一层
    protected Map<String, Object> getMap() {
        return this.extra;
    }
}
